using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using Entity;
namespace Bussiness
{
    public static class FileManage
    {

        public static int Add(Entity.File record)
        {
            object[] param = { record.name, record.path, record.flag, record.projectid, record.Id };

            return DataAccess.DB().ExecuteNonQuery("usp_InsertT_File", param);
        }

        public static List<Entity.File> GetProjectFiles(int projectid, bool isRoot)
        {
            List<Entity.File> result = new List<File>();
            object[] param = { projectid, isRoot };
            using (IDataReader reader = DataAccess.DB().ExecuteReader("usp_SelectT_File", param))
            {
                while (reader.Read())
                {
                    Entity.File tmp = new Entity.File(reader[0], reader[1], reader[2]);
                    result.Add(tmp);

                }
            }

            return result;
        }

        public static Entity.File GetFileByID(int Id)
        {
            Entity.File result = null;

            using (IDataReader reader = DataAccess.DB().ExecuteReader("usp_SelectT_FileByID", Id))
            {
                while (reader.Read())
                {
                    result = new File();
                    result.name = reader["name"].ToString();
                    result.path = reader["path"].ToString();

                }
            }

            return result;
        }
    }
}
